<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import = "mdoc.ejbsample.*,java.util.*,java.text.DateFormat,java.util.regex.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	  <link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Manager de cinema</title>
</head>
<body>
<center>
<h1>MDOC : Middlewares Orientés Composants</h1>
</center>
<%
	String film = request.getParameter("film");
	String cinema = request.getParameter("cinema");
	String heure = request.getParameter("heure");
	String minute = request.getParameter("minute");
	Cinema cine = (Cinema) session.getAttribute("cine");
	if (film==null){
		DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.FRANCE);
		Date t = df.parse(heure+":"+minute);
		//out.println("<p>Les films proposés apres "+heure+"h"+minute+" :");
		out.println("<form method=\"post\" action=\"reserver-jsp.jsp\">Choisissez votre séance :<br>");	
		Iterator<SalleProg> it = cine.getAllSalleProg().iterator();
		Iterator<Seance> it2;
		while (it.hasNext()){ 
			it2 = it.next().getSeance().iterator();
			while (it2.hasNext()){
				Seance s = it2.next();
				if (s.getHoraire().after(t)){
					out.println("<input type=\"radio\" name=\"choix\" value=\"" + s.getId() + "\"> " + s.toString() + "<br>");
					break;
				}
			}
		}
		out.println("<input type=\"submit\" value=\"Submit\">");
		out.println("<input type=\"reset\"	value=\"Reset\">");
		out.println("</form>");
	} else {
	//out.println("<p>Les films correspondant à votre recherche :");
	//out.println("<ul>");
	out.println("<form method=\"post\" action=\"reserver-jsp.jsp\">Choisissez votre séance :<br>");
	Iterator<Film> it = new HashSet<Film>(cine.getAllFilm()).iterator();
	while (it.hasNext()) {
		Film f = it.next();
		if (Pattern.matches(".*" + film + ".*", f.getName())) {
		
			Iterator<SalleProg> it3 = f.getSalles().iterator();
			Iterator<Seance> it2;
			while (it3.hasNext()){ 
				it2 = it3.next().getSeance().iterator();
				while (it2.hasNext()){
					Seance s = it2.next();
					out.println("<input type=\"radio\" name=\"choix\" value=\"" + s.getId() + "\"> " + s.toString() + "<br>");
				}
			}
		}
	}
		out.println("<input type=\"submit\" value=\"Submit\">");
		out.println("<input type=\"reset\"	value=\"Reset\">");
		out.println("</form>");
	}
%><br>

<a href="index.html">back</a>
</body>
</html>